package org.jaaksi.test.jasonpaser;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import org.jaaksi.test.jasonpaser.bean.BaseListInfo;
import org.jaaksi.test.jasonpaser.bean.BaseResultDataInfo;
import org.jaaksi.test.jasonpaser.bean.Student;
import org.jaaksi.test.jasonpaser.util.DataUtil;
import org.jaaksi.test.jasonpaser.util.RawUtils;

import java.lang.reflect.Type;

/**
 * 新版本gson,强大到让你窒息
 */
public class GsonActivity extends Activity {
    /**
     * Called when the activity is first created.
     */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        Gson mGson = DataUtil.mGson;
        String data = RawUtils.getJsonString(this, R.raw.array);

        Type type = new TypeToken<BaseResultDataInfo<BaseListInfo<Student>>>() {
        }.getType();
        BaseResultDataInfo<BaseListInfo<Student>> dataInfo = mGson.fromJson(data, type);
        Log.i("fcy", "----------------- " + dataInfo.data.list.get(0).toString());
    }
}
